
		
*******************************************************
* (1.0) Load the analysis sample 
*******************************************************
	use 			"$f_2PKbirthpanel", clear
	cap drop _merge
	merge m:1 prov year using `"$d_data\ProductionData.dta"'
	
	cap drop _merge
	merge m:1 prov year using `"$d_data\IMR.dta"'

	do `"$d_do\LLF_StackData.do"'

	gen years_since_LLF = year - LLFyear 
	global controls3 	" educ age_marriage U5MR_plt grain gdp pop_total_agric"
	
	global controls_69 ""
	foreach var of varlist $controls3 { 
		cap drop temp 
		gen temp = `var' if year == 1969
		bysort prov: egen `var'_69 = mean(temp)
		drop temp
		global controls_69 "$controls_69 `var'_69"
		
		} 
		
	global controls3 	"U5MR_plt grain gdp pop_total_agric"
	global controls_1prior ""
	foreach var of varlist $controls3 { 
		cap drop temp 
		gen temp = `var' if years_since_LLF == -1
		bysort prov: egen `var'_1prior = mean(temp)
		drop temp
		global controls_1prior "$controls_1prior `var'_69"
		
		} 

		
	drop if years_since_LLF<-8
	drop if year>=1980
	keep prov LLFyear years_since_LLF year $controls_69 $controls3 FE_prov FE_t
	bysort prov: gen temp = _n
	gen first = 1 if temp == 1
	
	drop if years_since_LLF<-10 
	drop if year>=1980
	
	forval i = 1/9 { 
		local j = abs(`i' - 11)
		cap drop years_prior`j'
		gen years_prior`j' = 0 if years_since_LLF !=.
		replace years_prior`j' = 1 if years_since_LLF == -`j'
		} 
		
	forval i = 1/11 { 
		local j = abs(`i' - 1)
		cap drop years_since`j'
		gen years_since`j' = 0 if years_since_LLF !=.
		replace years_since`j' = 1 if years_since_LLF == `j'
		} 
		
	keep prov LLFyear years_since_LLF years_prior10-years_prior2 years_since0-years_since10 year U5MR_plt grain gdp pop_total_agric FE_prov FE_t
	duplicates drop
		
	gen yline = 0

		
*******************************************************
* (2.0) Check secular trends  
*******************************************************
	
	*************
	* (2.1) GDP 
	*************
	
	xi: reg gdp  i.year i.prov, cluster(prov)
		cap drop resid_gdp
		predict resid_gdp, resid
		
		sum resid_gdp, detail
		local min = r(min)
		local max = r(max)
		local bottom = `min'*1.5
		local top = `max'*1.5

	cap drop low 
	cap drop high
	cap drop mean
	
	gen low = . 
	gen high = . 
	gen mean = . 
	
	forval i = 1/17 { 
		local j = `i' - 9
		sum resid_gdp if years_since_LLF == `j', detail 
		local low = r(p5)
		local high = r(p95)
		local mean = r(mean)
		replace low = `low' if years_since_LLF == `j'
		replace high = `high' if years_since_LLF == `j'
		replace mean = `mean' if years_since_LLF == `j'
		
	}
	 
	preserve 
	keep years_since_LLF low high mean yline
	duplicates drop
	drop if years_since_LLF <= -8 
	drop if years_since_LLF >= 8
	
		sum high, detail
		local max = r(max)
		local top = `max'*1.5
	
		sum low, detail
		local min = r(min)
		local bottom = `min'*1.5
			
	twoway 	(rcap low high years_since_LLF if years_since_LLF > -8 & years_since_LLF < 8) ///
			(connected mean years_since_LLF if years_since_LLF > -8 & years_since_LLF < 8, sort)  ///
			(line yline years_since_LLF if years_since_LLF > -8 & years_since_LLF < 8)  ///
			(pci `min' 0 `max' 0, lcolor(black)), /// 
			legend(off) yline(0)  title("Provincial GDP") /// 
			xtitle("Years Since LLF") xscale(range(-8, 8)) xlab(-8(1)8) xline(0) ///
			ytitle("Residuals") yscale(range(-15, 15))  
			
			graph export `"$d_fig\Fig_A7a_Pretrend.jpg"', replace		
	restore		

	**************
	* (2.2) U5MR 
	**************
	
	xi: reg U5MR_plt  i.year i.prov, cluster(prov)
		cap drop resid_U5MR_plt
		predict resid_U5MR_plt, resid
		
		sum resid_U5MR_plt, detail
		local min = r(min)
		local max = r(max)
		local bottom = `min'*1.5
		local top = `max'*1.5

	cap drop low 
	cap drop high
	cap drop mean
	
	gen low = . 
	gen high = . 
	gen mean = . 
	
	forval i = 1/17 { 
		local j = `i' - 9
		sum resid_U5MR_plt if years_since_LLF == `j', detail 
		local low = r(p5)
		local high = r(p95)
		local mean = r(mean)
		replace low = `low' if years_since_LLF == `j'
		replace high = `high' if years_since_LLF == `j'
		replace mean = `mean' if years_since_LLF == `j'
		
	}
	
	preserve 
	keep years_since_LLF low high mean yline
	duplicates drop
	drop if years_since_LLF < -8 
	drop if years_since_LLF > 8
	
		sum high, detail
		local max = r(max)
		local top = `max'*1.5
	
		sum low, detail
		local min = r(min)
		local bottom = `min'*1.5
		
	replace low = low*1000
	replace high = high * 1000
	replace mean = mean * 1000
	
	twoway 	(rcap low high years_since_LLF if years_since_LLF > -8 & years_since_LLF < 8) ///
			(connected mean years_since_LLF if years_since_LLF > -8 & years_since_LLF < 8, sort)  ///
			(line yline years_since_LLF if years_since_LLF > -8 & years_since_LLF < 8)  ///
			(pci `min' 0 `max' 0, lcolor(black)), /// 
			legend(off) yline(0)  title("Under Five Mortality Rate") /// 
			xtitle("Years Since LLF") xscale(range(-8, 8)) xlab(-8(1)8) xline(0) ///
			ytitle("Residuals") yscale(range(-15, 15))  
			
		graph export `"$d_fig\Fig_A7b_Pretrend.jpg"', replace		
	restore		

	******************
	* (2.3) Ag pop
	******************
	
	xi: reg pop_total_agric  i.year i.prov, cluster(prov)
		cap drop resid_pop_total_agric
		predict resid_pop_total_agric, resid
		
		sum resid_pop_total_agric, detail
		local min = r(min)
		local max = r(max)
		local bottom = `min'*1.5
		local top = `max'*1.5
	
	cap drop low 
	cap drop high
	cap drop mean
	
	gen low = . 
	gen high = . 
	gen mean = . 
	
	forval i = 1/17 { 
		local j = `i' - 9
		sum resid_pop_total_agric if years_since_LLF == `j', detail 
		local low = r(p5)
		local high = r(p95)
		local mean = r(mean)
		replace low = `low' if years_since_LLF == `j'
		replace high = `high' if years_since_LLF == `j'
		replace mean = `mean' if years_since_LLF == `j'
	}
	
	preserve 
	keep years_since_LLF low high mean yline
	duplicates drop
	drop if years_since_LLF <= -8 
	drop if years_since_LLF >= 8
	
		sum high, detail
		local max = r(max)
		local top = `max'*1.5
	
		sum low, detail
		local min = r(min)
		local bottom = `min'*1.5
		
	replace low = low*1000
	replace high = high * 1000
	replace mean = mean * 1000
	
	twoway 	(rcap low high years_since_LLF if years_since_LLF > -8 & years_since_LLF < 8) ///
			(connected mean years_since_LLF if years_since_LLF > -8 & years_since_LLF < 8, sort)  ///
			(line yline years_since_LLF if years_since_LLF > -8 & years_since_LLF < 8)  ///
			(pci `min' 0 `max' 0, lcolor(black)), /// 
			legend(off) yline(0)  title("Percentage of Population in Agriculture") /// 
			xtitle("Years Since LLF") xscale(range(-8, 8)) xlab(-8(1)8) xline(0) ///
			ytitle("Residuals") yscale(range(-15, 15))  
			
	graph export `"$d_fig\Fig_A7c_Pretrend.jpg"', replace							
	restore		
			
	**************
	* (2.4) Grain 
	**************
	
	xi: reg grain  i.year i.prov, cluster(prov)
		cap drop resid_grain
		predict resid_grain, resid
		
		sum resid_grain, detail
		local min = r(min)
		local max = r(max)
		local bottom = `min'*1.5
		local top = `max'*1.5
	
	cap drop low 
	cap drop high
	cap drop mean
	
	gen low = . 
	gen high = . 
	gen mean = . 
	
	forval i = 1/17 { 
		local j = `i' - 9
		sum resid_grain if years_since_LLF == `j', detail 
		local low = r(p5)
		local high = r(p95)
		local mean = r(mean)
		replace low = `low' if years_since_LLF == `j'
		replace high = `high' if years_since_LLF == `j'
		replace mean = `mean' if years_since_LLF == `j'
	}
	
	preserve 
	keep years_since_LLF low high mean yline
	duplicates drop
	drop if years_since_LLF <= -8 
	drop if years_since_LLF >= 8
	
		sum high, detail
		local max = r(max)
		local top = `max'*1.5
	
		sum low, detail
		local min = r(min)
		local bottom = `min'*1.5
		
	replace low = low*1000
	replace high = high * 1000
	replace mean = mean * 1000
	
	twoway 	(rcap low high years_since_LLF if years_since_LLF > -8 & years_since_LLF < 8) ///
			(connected mean years_since_LLF if years_since_LLF > -8 & years_since_LLF < 8, sort)  ///
			(line yline years_since_LLF if years_since_LLF > -8 & years_since_LLF < 8)  ///
			(pci `min' 0 `max' 0, lcolor(black)), /// 
			legend(off) yline(0)  title("Grain Output (1000 tons)") /// 
			xtitle("Years Since LLF") xscale(range(-8, 8)) xlab(-8(1)8) xline(0) ///
			ytitle("Residuals") yscale(range(-15, 15))  
		
			graph export `"$d_fig\Fig_A7d_Pretrend.jpg"', replace		
	restore		


